package workspace.day161012;

import java.nio.channels.ScatteringByteChannel;
import java.util.Scanner;

import javax.print.DocFlavor.CHAR_ARRAY;

import org.junit.Test;

public class day {

	@Test
	public void day01(){
		System.out.println("请输入两个数");
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a>b) {
			int c = a;
			a = b;
			b = c;
			System.out.println("输出结果为"+a+""+b);
			
		}
		
	}

//判断一个数为水仙花数
//水仙花数就是一个数 由数本身的数字的立方的和组成的数就叫水仙花数
	//首先要判定该数是一个整数 而且这个数不能大于1000,小于100
	//其次 再来判定该数是否由数本身数字立方和组成
   @Test
   public void day02(){
	   System.out.println("请输入一个整数");
	   Scanner sc =new Scanner(System.in);
	   int num = sc.nextInt();
		  if(b(num)){
			  System.out.println(num+ "该数是水仙花数");
		  }
		  else {
			System.out.println(num+ "该数不是水仙花数");
		}
     }
	  
	    // 用于判断一个整数是否是水仙花数  
	    public static boolean b(int i) {  
	        boolean flag = true;  
	  
	        int a = i / 100; // 取得百位数  
	        int b = (i / 10) % 10; // 取得十位数  
	        int c = i % 10; // 取得个位数  
	        /* 
	         * if ((Math.pow(a, 3) + Math.pow(b, 3) + Math.pow(c, 3)) != i) {// 若各位数字立方和不等于该数本身 
	         *       flag = false;// 返回false  
	         * } 
	         */  
	        if (a * a * a + b * b * b + c * c * c != i) {// 若各位数字立方和不等于该数本身  
	            flag = false;//返回false  
	        }  
	        return flag;  
	    }  
	    @Test
		public void day03(){
			System.out.println("请输入两个数");
			Scanner sc = new Scanner(System.in);
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c; 
	/*		if (a>b) {
				c = a;
				System.out.println("MAX"+c);
			}
			else {
				c= b;
				System.out.println("MAX" +b);
			}
		*/ c= a>b?a:b;
		System.out.println("结果为："+c);
		}
/**switch 只表述等于的关系
 * 
 */
	    @Test
		public void day04(){
	    	System.out.println("请输入年龄....  10 20 30 40 50 60");
	    	Scanner sc =new Scanner(System.in);
	    	int age = sc.nextInt();
	    	switch(age){
	    	case  10: System.out.println("少年"); break;
	    	case  20: System.out.println("青年"); break;
	    	case  30: System.out.println("成年"); break;
	    	case  40: System.out.println("中年"); break;
	    	case  50: System.out.println("中老年"); break;
	    	default: System.out.println("老年"); break;
	    	}
	    	sc.close();
	    }
	    @Test
	    public void day05(){
	    	Scanner sc =new Scanner(System.in);
	    	System.out.println("请输入第一个数");
	    	int a = sc.nextInt();
	    	System.out.println("请输入第二个数");
	    	int b = sc.nextInt();
	    	System.out.println("请输入符号");
	    	char x=sc.next().charAt(0);
	    	switch(x){
	    	case  '+': System.out.println(a+b); break;
	    	case  '-': System.out.println(a-b); break;
	    	case  '*': System.out.println(a*b); break;
	    	case  '/': System.out.println(a/b); break;
	    	case  '%': System.out.println(a%b); break;
	    	default: System.out.println("出现错误"); break;
	    	}
	    	sc.close();
	    }
	    @Test
	    public void day06(){
	    	int i=1;
	    	int J=0;
	    	int Z=0;
	    	int a=1;
	    	while(i<=100){
	    		if(i%2!=0){
	    			J=J+i;
	    		}	
	    		if(i%3==0){
	    			Z=Z+i;
	    		}
					i=i+1;
					a=a+1;
	    		System.out.println("100以内所有能被3整除的数的和为："+Z);
	    		System.out.println("100以内所有的奇数和为："+J);
	    		System.out.println("计算次数为："+a);
	    	}
	    	
	    }
	    /**
	     * do while编写时 要先编写计算程序  然后再来编写条件改变程序
	     */
	    @Test
	    public void day07(){
	    	int begin = 1;
	    	int end = 100;
	    	int sum = 0;
	    	do {
				sum= sum+begin;
				begin=begin+1;
			} while (begin<=end);
	    	System.out.println(sum);
	    }
	    /**
	     * for语句是用于 变量关系可以用加减法来确定的语句
	     */
	    @Test
	    public void day08(){
	    	int sum=0;
	    	for (int begin = 0; begin <= 100; begin=begin+3) {
				sum+=begin;
			}
	    	System.out.println(sum);
	    } 
	    @Test
	    public void day09(){
	    	int sum =1;
/*	    	int i=1;
	    	while (i<=10) {
				if (i%2==0) {
					sum=sum*i;
				}
				i++;
*/	
			for (int i = 2; i <=10; i=i+2) {
	         sum = sum*i;
	         }		
			System.out.println(sum);  
     }
	    @Test
	    public void day10(){
	    	for (int outer = 1; outer <=5; outer=outer+1) {
	    		for (int jiange = 5; jiange >outer; jiange=jiange-1) {
	    			System.out.print("* ");
				}
	    		System.out.print("\r\n");
			}
	    }	 
	    /**
	     * while使用于
	     */
	    @Test
	    public void day11(){
	    	int i=1;
	    	for (int you = 1; you <=3; you=you+1) {
	    		for (int j = 0; j <6; j++) {
				System.out.println("***" );
			}
			}System.out.print(" ");
	    }    
}
   
   
   
   
   
   
   
   
   
   
   
 
   
   
   
   
   
   